<%@ page language="java" import="java.util.*" contentType="text/html"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>修改试卷</title>
	<script charset="utf-8" src='<c:url value="/js/jquery.min.js"></c:url>'></script>
	<script type="text/javascript" src='<c:url value="/js/boot.js"></c:url>'></script>
	<script type="text/javascript"
		src='<c:url value="/js/rqfui/rqfui.js"></c:url>'></script>
	<style>
		html,body{
			margin: 0;
			padding: 0;
			font-family: "微软雅黑";
		}
		li{
			list-style: none;
		}
		a{
			text-decoration: none;
		}
		.Basic_course_content{
			width: 1920px;
			width: 100%;
		}
		.Basic_course_content_content{
			width: 1280px;
			margin: 0 auto;
		}
		.Basic_course_content_content_content{
			width: 780px;
 		    margin-left: 104px;
    		margin-top: 24px;
			text-align: left;
		}
		.Basic_course_content_content_content_title{
			color: #b8b8b8;
			font-size: 16px;
			padding-bottom: 1px;
			border-bottom: 2px solid #2459aa;
			font-weight: 800;
		}
		.Basic_course_content_content_content_title ul{
			padding:0;
			margin:10px;
		}
		.Basic_course_content_content_content_title li{
			display: inline-block;
			margin-right: 55px;
		}
		.Basic_course_content_content_content_title div{
			display: inline-block;
			height: 20px;
			width: 20px;
			border-radius: 50%;
			background: #b8b8b8;
		}
		.Basic_course_content_content_content_title li>div>span{
			color:white;
			z-index:1;
			position:relative;
			left:6px;
			top:-2px;
			font-weight:800;
			font-size:13px;
		}
		.Basic_course_content_content_content_content{
			padding: 25px 0;
		}
		.Basic_course_content_content_content_content>ul>li{
			padding: 16px 0;
		}
		.Basic_course_content_content_content_content>ul{
			margin: 0;
			padding: 0;
			margin-bottom: 16px;
		}
		.Basic_course_content_content_content_content>ul>li>div>span{
			/*float: left;*/
			font-size: 16px;
			padding: 4px 0;
		}
		.Basic_course_content_content_content_content>ul>li>div>span>font{
			color: #ff0000;
		}
		.Basic_course_content_content_content_content>ul>li>div>input{
			width: 420px;
			padding: 5px 0;
			padding-left: 5px;
		}
		.Basic_course_content_content_content_content>ul>li>div>select{
			padding: 5px 0;
			padding-left: 5px;
		}
		.Basic_course_content_content_content_content>ul>li>div>textarea{
			width: 420px;
			padding: 5px;
    		margin-top: 5px;
		}
		.Basic_course_content_content_content_content>ul>li>div>select>option{
			padding: 3px;
		}
		.Basic_course_baocun{
			width: 78px;
			height: 32px;
			text-align: center;
			background: #2459aa;
			color: #fff;
			font-size: 16px;
			line-height: 32px;
			border-radius: 3px;
			margin-left: 92px;
			display: inline-block;
			margin-right: 30px;
			cursor: pointer;
		}

		.fixedWidth{
			width: 22px;
		}
		.inlineDisplay{
			display: inline-block;	
		}


		/*以下是弹出框*/
		.select_course_type_content{
			z-index: 999;
			width: 430px;
			height: 565px;
			position: absolute;
			top: 130px;
			left: calc(50% - 215px);
			background:#fff;
			box-shadow: 0 0 3px #ccc;
			border-radius: 4px;
		}
		.select_course_type_content_header{
			width: 430px;
			height: 34px;
			background: #2b5eae;
			border-top-left-radius: 4px;
			border-top-right-radius: 4px;
		}
		.select_course_type_content_header img{
			border-top-right-radius: 4px;
		}
		.select_course_type_content,.select_course_type_content_header>span{
			font-size:14px;
			color:#fff;
			line-height:34px;
			margin-left:8px;
		}
		.cancel{
			width: 49px;
			height: 34px;
			float:right;
			cursor: pointer;
		}
		.select_course_type_content_content{
			/*text-align: center;*/
		}
		.select_course_type_content_content>span{
			line-height: 140px;
			font-size:16px;
			color:#2b5eae;
		}



		/*以下是弹出框表格*/
		.table{
			text-align: center;
			width: 95%;
		    margin-bottom: 20px;
		    margin: auto;
			color: black;
		    border-spacing: 0;
		    border-collapse: collapse;
		}

		.case_table>tbody>tr:nth-child(even){
			background: #f5f8fd;
		}
		.case_table>tbody>tr{
			cursor: pointer;
			border: 1px solid #ddd;
		}
		.case_table>tbody>tr:last-child{
			border-bottom: 1px solid #ddd;
		}
		tr {
		    display: table-row;
		    vertical-align: inherit;
		    border-color: inherit;
		}
		td {
		    display: table-cell;
		    vertical-align: inherit;
		    padding: 8px;
		    line-height: 1.42857143;
		    vertical-align: top;
		    border-top: 1px solid #ddd;
		}
		.pagination {
		    display: inline-block;
		    padding-left: 0;
		    margin: 20px 0;
		    border-radius: 4px;
		   }
		.table tr>td:first-child{
			width: 40px;
		}
		.table tr>td:last-child{
			text-align: left;
		}
		/*表格*/

		/*以下是弹出框分页*/
	    nav{
	    	text-align: center;
	    	display: block;
	    	box-sizing: border-box;
	    }
	    nav li{
			display: inline-block;
	    	text-align: -webkit-match-parent;
		}
	    .pagination>li>a, .pagination>li>span {
		    position: relative;
		    float: left;
		    padding: 6px 12px;
		    margin-left: -5px;
		    line-height: 1.42857143;
		    color: #337ab7;
		    text-decoration: none;
		    background-color: #fff;
		    border: 1px solid #ddd;
		}
		.pagination>li:first-child>a, .pagination>li:first-child>span {
		    border-top-left-radius: 4px;
		    border-bottom-left-radius: 4px;
		}
		.pagination>li:last-child>a, .pagination>li:last-child>span {
		    border-top-right-radius: 4px;
		    border-bottom-right-radius: 4px;
		}
		.confirm_select{
			width: 78px;
		    height: 32px;
		    text-align: center;
		    background: #2459aa;
		    color: #fff;
		    font-size: 14px;
		    line-height: 32px;
		    border-radius: 3px;
		    margin-left: 92px;
		    display: inline-block;
		    margin: 9px 20px;
		}
		/*分页*/

/*  */

		.mini-buttonedit-border {
    		height: 29px;
    	}
	    .mini-buttonedit-icon {
	    	margin-top:6px !important;
		}
		.mini-buttonedit-button {
		    height: 29px !important;
		}
    	.mini-buttonedit-border, .mini-textbox-border {
    		border-radius: 0px !important;
    	}
    	.mini-buttonedit-input {

		    height: 29px !important;
		}
		.mini-buttonedit-border {
    		border-color: #b3acac;
    	}
/*  */



	</style>
</head>
<body>
	<div class="Basic_course_content">
		<div class="Basic_course_content_content">
			<div class="Basic_course_content_content_content">
				<div class="Basic_course_content_content_content_title">
					<ul>
						<li style="color:#2459aa;">
							<div style="color:#2459aa;background:#2459aa;"><span style="">1</span></div>
							<span>新建试卷</span>
						</li>
						<li>
							<div><span>2</span></div>
							<span>试卷组装</span>
						</li>
						<li>
							<div><span>3</span></div>
							<span>设置试卷</span>
						</li>
					</ul>
				</div>
				<div class="Basic_course_content_content_content_content">
					<ul>
						<li>
							<div>
								<span><font>*</font> 试卷名称：</span>
								<input type="text" id = "paperName" />
							</div>
						</li>
						<li>
							<div>
								<span><font>*</font> 试卷类型：</span>
								<select id="select_paper_type" style="color:#2459aa;width:200px; cursor:pointer;"> 
							    </select>
							    <!-- <span style="color:#b8b8b8;position:relative;left:-200px;font-size:14px;">请选择</span> -->
							</div>
						</li>
						<li>
							<div>
								<span><font>&nbsp;</font> 所属课程：</span> <input id="lookup2"
									name="look" class="mini-lookup"
									style="width: 432px; height: 32px;" textField="class_name"
									valueField="id" popupWidth="auto" popup="#gridPanel"
									grid="#datagrid1" multiSelect="true" value="" text="" />
								<div id="gridPanel" class="mini-panel" title="header"
									iconCls="icon-add" style="width: 450px; height: 250px;"
									showToolbar="true" showCloseButton="true" showHeader="false"
									bodyStyle="padding:0" borderStyle="border:0">
									<div property="toolbar"
										style="padding: 5px; padding-left: 8px; text-align: center;">
										<div style="float: left; padding-bottom: 2px;">
											<span>课程：</span> <input id="keyText" class="mini-textbox"
												style="width: 160px;" onenter="onSearchClick" /> <a
												class="mini-button" onclick="onSearchClick">查询</a> <a
												class="mini-button" onclick="onClearClick">清除</a>
										</div>
										<div style="float: right; padding-bottom: 2px;">
											<a class="mini-button" onclick="onCloseClick">关闭</a>
										</div>
										<!-- <div style="clear: both;"></div> -->
									</div>
									<div id="datagrid1" class="mini-datagrid"
										style="width: 100%; height: 100%;" borderStyle="border:0"
										showPageSize="false" showPageIndex="false" url=''>
										<div property="columns">
											<div type="checkcolumn"></div>
											<div field="class_name" width="120" headerAlign="center"
												allowSort="true">课程</div>
											<div field="creater" width="120" headerAlign="center"
												allowSort="true">编制人</div>
											<div field="createTime" width="100" headerAlign="center"
												dateFormat="yyyy-MM-dd" allowSort="true">创建日期</div>
										</div>
									</div>
								</div>
							</div>
						</li>
						<li>
							<div>
								<span><font>*</font> 试卷时长：</span>
								<input id = "time" type="text" style="border: 1px solid #ccc;width:200px;" 
								 onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">
								<span>分钟</span>
							</div>
						</li>
						<li id="edit_article">
							<div class="Basic_course_modify">
								<span><font>*</font> 打分方式：</span>
								<div class="inlineDisplay">
									<input type="radio" style="" id="auto" name="grading_way" value = "1"><label for="auto" class="fixedWidth ">自动</label for="">
								</div>
								<div class="inlineDisplay">
									<input type="radio" style="" id="hand" name="grading_way" value = "0"><label for="hand" class="fixedWidth">手动</label for="">
								</div>
								<span style="font-size:14px;color:red;">（说明：试卷设置为自动打分将不能添加解答题型）</span>
							</div>
						</li>
					</ul> 
					<a class="Basic_course_baocun" href = "javascript:save()">保存</a>
					<a class="Basic_course_baocun" href="javascript:next()" >下一步</a>
				</div>
			</div>
		</div>
	</div>
</body>
<script>
	mini.parse();
	mini_debugger = false;
	var rootPath = '${rootPath}';
	var datagrid1 = mini.get("datagrid1");
	var keyText = mini.get("keyText");
	var filterHelper = gridFilter();
	var lookup2 = mini.get("lookup2");
	var paperId = '${paperId}';
	var isSave = false;
	var grading_way ="";
	$("#select_course_type").click(function(){
		$(".select_course_type_content").show();
	});
	$(".cancel").click(function(){
		$(".select_course_type_content").hide();
	});
	$(function(){
		getTypeList();
		getMap(paperId);
	})
	$("#select_paper_type").change(function() {
		var value = $("#select_paper_type").val();
		onSearchClick(value);
	});
	function onSearchClick(str) {
		var key = keyText.getValue();
		filterHelper.clearFilterData();
		if (key != "") {
			var filterdata = filterHelper.formFilterData("class_name",
					key, '', 'CONTAIN', 'AND');
			filterHelper.addFilterData(filterdata);
		}
		if (str != "") {
			var filterdata = filterHelper.formFilterData("class_id",
					str, '', 'CONTAIN', 'AND');
			filterHelper.addFilterData(filterdata);
		}
		loadGrid1();
    }
	
	function getMap(id){
		var url = rootPath +"/testPaper/mapData/" + id;
		$.ajax({
			url:url,
			method:"post",
			dataType:"json",
			data:{},
			success:function(data){
				if(data){
					$("#paperName").val(data.name);//试卷名称
			    	$("#select_paper_type").val(data.class_id);//试卷类型
			    	lookup2.setText(data.courseName);//所属课程
			    	$("#time").val(data.time);//答题时间
			    	if(data.isAuto == 1){
			    		grading_way = "auto";
				    	$("input[name=grading_way]:eq(0)").attr("checked",'checked');
			    	}else{
			    		grading_way = "hand";
				    	$("input[name=grading_way]:eq(1)").attr("checked",'checked');
			    	}
				}
			},
			error:function(){
				top.commonTools.showTip("失败！", 2);
			}
		});
	}
	function loadGrid1() {
		var filterData = filterHelper.getFilterData();
		var postData = new Object();
		if (filterData != null || filterData.length > 0) {
			postData.filterdata = mini.encode(filterData);
		}
		var url = "<c:url value='/question/courseList' />";
		datagrid1.load(url);
		datagrid1.load(postData);
	}
	function onCloseClick(e) {
        lookup2.hidePopup();
    }
    function onClearClick(e) {
        lookup2.deselectAll();
        keyText.setValue();
        filterHelper.clearFilterData();
        loadGrid1();
    }
	
	function getTypeList(){
		var url = rootPath +"/class/typeList";
		$.ajax({
			url:url,
			method:"post",
			dataType:"json",
			data:{},
			success:function(data){
				var htmStr = "<option>请选择</option>";
				if(data){
					for(var i = 0; i < data.length;i++){
						htmStr +="<option value = \""+data[i].id+"\">"+data[i].name+"</option>"
					}
				}
				$("#select_paper_type").html(htmStr);
			}
		});
		
	}

    function save(callBackfunction){
    	var grading_way;
    	var url = rootPath + "/testPaper/update/"+paperId;
    	var paperName = $("#paperName").val();//试卷名称
    	if(!paperName){
    		top.commonTools.showTip("请填写试卷名称！", 2);
    		return;
    	}
    	var class_id = $("#select_paper_type").val();//试卷类型
    	if(class_id == "请选择"){
    		top.commonTools.showTip("请选择类型", 2);
    		return;
    	}
    	var course_id = lookup2.getValue();
    	var course_name = lookup2.getText();//所属课程
    	/* if(!course_name){
    		top.commonTools.showTip("请选择所属课程！", 2);
    		return;
    	} */
    	var time = $("#time").val();//答题时间
    	if(!time){
    		top.commonTools.showTip("请设置答题时间!", 2);
    		return;
    	}
    	var handleWay = $("input[name='grading_way']:checked").val();//打分方式
    	if(!handleWay){
    		top.commonTools.showTip("请设置打分方式!", 2);
    		return;
    	}
    	if(handleWay == 1){
    		grading_way = "auto";
    	}else{
    		grading_way ="hand";
    	}
    	var map = new Object;
    	map.name = paperName;
    	map.class_id = class_id;
    	map.courseId = course_id;
    	map.courseName = course_name;
    	map.time = time;
    	map.isAuto = handleWay;
    	var jsonData = JSON.stringify(map);
    	$.ajax({
    		url:url,
    		method:"post",
    		dataType:"json",
    		data:{'data':jsonData},
    		success:function(data){
    			if(data){
    				isSave = true;
    				if(callBackfunction){
    					callBackfunction();
    				}else{
    					top.commonTools.showTip("保存成功!", 1);
    				}
    			}
    		},
    		error:function(){
    			top.commonTools.showTip("保存失败!", 2);
    		},
    		complete:function(){
    			
    		}
    	});
    }
    
    function next() {
		if(isSave){
			location.href = rootPath + "/testPaper/packages_r/" + grading_way
			+ "/" + paperId;
		}else{
			save(function() {
				location.href = rootPath + "/testPaper/packages_r/" + grading_way
						+ "/" + paperId;
			});
		}
	}
</script>
</html>